<template>
	<view class="app">
		<view class="main">
			<view class="wxlogin">
				<view class="logo">
					<view class="posi-abs"></view>
					<image :src="config.logo"></image>
				</view>
				<view class="appname">{{config.name}}</view>
				<view class="subname">工衣票选</view>
				<view class="btn"><button @tap="wxAuth" :disabled="!confisLoad">微信一键登录</button></view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				confisLoad: false,
				config: {},
				pagequery:{}
			}
		},
		methods: {
			wxAuth() {
				console.log(location);
				const backurl = this.pagequery.redirect_uri?this.pagequery.redirect_uri:location.origin + location.pathname + '#/';
				const redirect_uri=location.protocol + '//' + location.host + location.pathname + location.hash + '?redirect_uri=' + encodeURIComponent(backurl);
				const redirect_url2 = this.$comm.servDomain  + '/api/wechat/jump?url=' + encodeURIComponent(redirect_uri);
				const url=`https://open.weixin.qq.com/connect/oauth2/authorize?appid=${this.config.wx_config.oa_app_id}&redirect_uri=${encodeURIComponent(redirect_url2)}&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect`;
				location.href=url;
				console.log('1121', backurl);
			},
			loadConfig() {
				return new Promise((resolve, reject) => {
					this.$comm.http('/api/index/shareConfig').then(res => {
						this.confisLoad = true;
						this.config = res.data;
						this.config.wx_config = JSON.parse(res.data.wx_config);
					})
				});
			}
		},
		onLoad(e) {
			// uni.login({
			// 	provider: 'weixin',
			// 	onlyAuthorize: true,
			// 	success: function(loginRes) {
			// 		console.log(loginRes);
			// 		// 登录成功
			// 		uni.getUserInfo({
			// 			provider: 'weixin',
			// 			success: function(info) {
			// 				// 获取用户信息成功, info.authResult保存用户信息
			// 			}
			// 		})
			// 	},
			// 	fail: function(err) {
			// 		console.log(err);
			// 		// 登录授权失败
			// 		// err.code是错误码
			// 	}
			// });
			this.loadConfig()
			console.log(e);
		}
	}
</script>

<style lang="scss">
	.main {
		height: 100vh;
	}

	.wxlogin {
		display: flex;
		flex-direction: column;
		align-items: center;
		align-content: center;
		font-size: 12px;
		padding-top: 25px;
		line-height: 25px;

		.appname {
			font-size: 20px;
			font-weight: bold;
		}

		.logo {
			position: relative;

			.posi-abs {
				width: 32px;
				height: 6px;
				opacity: 0.3;
				background: rgb(76, 184, 144);
				border-radius: 50%;
				filter: blur(1px);
				bottom: 3px;
				position: absolute;
				left: 50%;
				transform: translateX(-50%);
			}

			image {
				width: 58px;
				height: 58px;
				border-radius: 50%;
				position: relative;
			}
		}
	}

	.btn {
		margin: 60px 0 0;
	}

	.btn button {
		height: 37px;
		line-height: 37px;
		font-size: 13px;
		width: 70vw;
		border: none;
		background-color: rgb(56, 152, 124);
		color: #fff;
		border-radius: 6px;
	}
</style>